﻿@using TestListInModel.Models; 

@model theModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}s

<h2>Index</h2>

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "form" }))
{
    <table>
        @foreach (theEntity item in Model.EntityList)
        {
            @Html.Partial("_thePartial", item)
        }
    </table>
    <input type="button" id="btn_add" value="add a record"/>
    <input type="button" id="btn_post" value="Go to post !!!!!!!!"/>
}
 <script type="text/javascript">
    $(document).ready(function () {
        $('#btn_post').click(function () {
            form.submit();
        });

        $('#btn_add').click(function () {
            $.ajax({
                url: '@Url.Action("theAjaxPost", "Home")', 
                type: 'POST',
                success: function(result) {
                    $('table').append( result );
                },
                error: function(result)
                {
                    alert('une erreur s\'est produite');
                }
            })
        });
    });
</script>